/*
 * Copyright (c) 2009, Hamish Morgan
 * All rights reserver.
 */
package locusts.common;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import locusts.client.Client;
import locusts.common.GameConfig;
import locusts.common.WorldModel;
import locusts.server.Game;
import locusts.server.Server;
import locusts.server.ServerConfig;

/**
 *
 * @author Hamish Morgan
 */
public class Main {

    /**
     * @param args the command line arguments
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        if (args.length == 0) {
            Game g = new Game(new WorldModel(), new GameConfig());
            g.start();
            new Server(g, new ServerConfig()).start();
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).
                        log(Level.SEVERE, null, ex);
            }
            new Client("localhost", 9123, "Unamed Player");

        } else if (args[0].equals("server")) {
            Game g = new Game(new WorldModel(), new GameConfig());
            g.start();
            new Server(g, new ServerConfig()).start();
        } else {
            new Client(args[0], Integer.parseInt(args[1]), args[2]);
        }
    }
}
